@extends('layouts.default')

@section('title', '')

@push('scripts')
<script src="{{ asset('lib/xm-select-v1.2.4/xm-select.js')}}"></script>
<script>
    layui.config({
        base: '/lib/Pear-Admin-Layui-next/component/pear/module/'
    }).extend({
        tableMerge: 'tableMerge'
    });
    layui.use(['layer','form','table','laytpl','laydate','element','laypage','upload','tableMerge'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var element = layui.element;
        var laypage = layui.laypage;
        var upload = layui.upload;
        var tableMerge = layui.tableMerge;
        var xmDemo;
        var xmDemo2;
        var xmDemo3; //调取资料时间
        var xmDemo4; //岗位级别
        var xmDemo5; //参与老师
        var id = "{{request()->get('id',0)}}";
        var ct_id = "{{request()->get('ct_id',0)}}";
        var scale_id = "{{request()->get('scale_id',0)}}";
        var username = "{{request()->get('username','')}}";
        var user_id = "{{request()->get('user_id',0)}}"; //老师账号

        laydate.render({
            elem: '#check_start'
        });
        laydate.render({
            elem: '#check_end'
        });
        laydate.render({
            elem: '#submit_start'
        });
        laydate.render({
            elem: '#submit_end'
        });

    

        renderSelect(function(){
            //编辑
            if(id != 0){
                getTeacherBaseInfo2({'id':id,user_id:user_id,ct_id:ct_id},function(res){
                    if(res.code == 1){
                        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值                     
                            'data_version_name': res.data.data_version_name,
                            'username': res.data.username,                       
                            'subject': res.data.subject,                       
                            'grade': res.data.grade,                       
                            'class': res.data.class,                       
                            'title': res.data.title,                       
                            'zf': res.data.zf,                       
                            'pjf': res.data.pjf,                       
                            'rank': res.data.pm != ''?res.data.pm.ranks+'/'+res.data.pm.rank_sum:'',                       
                        });
                        
                        
                    }
                })

                getCheckScaleInfo({'id':id,scale_id:scale_id,user_id:user_id,ct_id:ct_id},function(res){
                    if(res.code == 1){
                        if(res.data.table_data.length>0){
                            let tier = res.data.table_data[0].tier;
                            var cols = [];
                            cols.push({type: 'numbers', title: '序号'});
                            for (let i2 = 1;i2<=tier;i2++) { 
                                if(i2 == 1){
                                    cols.push({field: 'title1',merge: 'title1', title: '一级指标'});
                                }else if(i2 == 2){
                                    cols.push({field: 'title2',merge: 'title2', title: '二级指标'});
                                }else if(i2 == 3){
                                    cols.push({field: 'title3',merge: 'title3', title: '三级指标'});
                                }else if(i2 == 4){
                                    cols.push({field: 'title4',merge: 'title4', title: '四级指标'});
                                }                         
                            }
                            
                            delete cols[tier-1].merge; //最后一级指标不需要合并
                            cols.push({field: 'check_module_text', title: '参考材料', width:'30%',style:"height:auto",templet:'#titleTpl2'});
                            //cols.push({field: 'score', title: '单项分数', align: 'center',edit: 'text'});
                            cols.push({field: '', title: '打分', align: 'center',style:'height:auto;padding: 0px 15px',templet:'#titleTpl'});
                            //console.log(res.data.table_data);
                            table.render({
                                elem: '#tablelist'
                                ,limit: 300
                                ,data: res.data.table_data
                                ,css:'.layui-table-main{border-left: 1px #eee solid;border-right: 1px #eee solid;border-bottom:1px #eee solid}'
                                //,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                                ,cols: [cols]
                                ,done: function(res, curr, count){
                                    tableMerge.render(this);
                                }
                            });
                       }
                    }
                })
            }          
        });
    
        //下拉框初始化
        async function renderSelect(callback){   
            callback();
        }  


        //评分模块查看
        $(document).on('click','.module-see',function(){
            let data = $.parseJSON($(this).attr('data'));  
            let materials_date = data.materials_array; 
           // console.log(data);
            switch(data.module_id){
                case '4':
                    var title = '经验交流 - 查看';
                    var url = "{{route('rating.check.jyjl')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '5':
                    var title = '课题研究 - 查看';
                    var url = "{{route('rating.check.ktyj')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '6':
                    var title = '论文发表 - 查看';
                    var url = "{{route('rating.check.lwfb')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '7':
                    var title = '论著发表 - 查看';
                    var url = "{{route('rating.check.lzfb')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                case '19':
                    var title = '带教情况 - 查看';
                    var url = "{{route('rating.check.djqk')}}?materials_date="+JSON.parse(materials_date)+'&user_id='+user_id;
                    break;
                default:
                
            }

            layer.open({
                title :title,
                type: 2, 
                content: url ,
                area: ['1400px', '800px'],
                btn: [ '取消'],
                btnAlign: 'c',
                yes: function(index, layero){
                    layer.closeAll();
                }
                
            }); 
        })

        window.fc_check_scores = function aa(obj){
            let data = $.parseJSON(obj.attr('data')); 
            let single_score = parseFloat(data.single_score); //单项最大分
            let default_score = parseFloat(data.default_score); //单项默认分
            obj.val(obj.val().replace(/^[.]{0,1}|[.]{0,1}$/g, "")); //去掉首尾的点
            let score = parseFloat(obj.val()); 
            if(isNaN(score)) {
                let val = {
                    'scale_id':data.id,
                    'scores':default_score,
                    'top_id':data.top_id,
                };
                obj.val(default_score); 
                obj.next().val(JSON.stringify(val));
                return false;
            }
            if(single_score != 0 && score >single_score){
                layer.msg('评分不能超过'+single_score+'分');
                obj.val(single_score)
                score = single_score;
            } 
            
            obj.val(score);          
    
            let val = {
                'scale_id':data.id,
                'scores':score,
                'top_id':data.top_id,
            };
            obj.next().val(JSON.stringify(val));
        }

        //提交
        $('#formDemo').click(function(){
            let form_data = form.val('formTest2');//表单提交数据
            form_data.id = id;
            form_data.ct_id = ct_id;
            form_data.user_id = user_id;
            form_data.username = username;
            //console.log(form_data);
            checkScores(form_data,function(res){
                if(res.code == '1'){
                    if(res.data.tips.length>0){
                        layer.open({
                            title :'提示',
                            type: 1, 
                            content: $('#tips-view') ,
                            area: ['600px', '350px'],
                            btn: [ '确定','取消'],
                            btnAlign: 'c',
                            yes: function(index, layero){
                                form_data.is_pass = 1;
                                checkScores(form_data,function(res2){
                                    if(res.code == '1'){
                                        layer.msg(res.msg,{icon: 6,time: 1000},function(){
                                           // window.history.back();
                                           $("#queryBtn" , parent.document).click();
                                            parent.layer.closeAll();
                                        });
                                    }else{
                                        layer.msg(res.msg, {icon: 5,shift : 6});
                                    }
                                })
                            },
                            btn2: function(index, layero){
                            },  
                            success: function(layero, index){
                                let getTpl = tips.innerHTML
                                ,view = document.getElementById('tips-view');
                                laytpl(getTpl).render(res.data.tips, function(html){
                                view.innerHTML = html;
                                });
                            }
                        }); 
                    }else{
                        layer.msg(res.msg,{icon: 6,time: 1000},function(){
                            //window.history.back();
                            $("#queryBtn" , parent.document).click();
                            parent.layer.closeAll();
                        });
                    }                   
                }else{
                    layer.msg(res.msg, {icon: 5,shift : 6});
                }
            })
        })


        $('#fanhui').click(function(){
            parent.layer.closeAll();
        })
               
    });
</script>
<script type="text/html" id="tips">  
    @{{#  layui.each(d, function(index, item){ }}
        <p>提示@{{++index}}：@{{- item}}</p>
    @{{#  }); }}
    <p>是否确认提交当前操作？</p>
</script>
<script type="text/html" id="titleTpl">   
    <input onchange="fc_check_scores($(this))" data="@{{JSON.stringify(d)}}" type="number" max="@{{# if(d.single_score == 0.0){ }}1000@{{# }else{ }}@{{d.single_score}}@{{# } }}" min="0"  name="scores[]" value="@{{# if(d.pf_score_json != ''){ }}@{{d.pf_score_json.scores}}@{{# }else{ }}@{{d.default_score}}@{{# } }}" autocomplete="off" required  lay-verify="required" lay-reqText="请填写分数" class="layui-input verify-score mark_score" onkeyup="value=value.replace(/[^\d.]/g,'').replace(/\.{2,}/g,'.').replace(/^(\-)*(\d+)\.(\d).*$/,'$1$2.$3')" style="text-align: center;">
    <input type="text" name="scores2[]" value="@{{# if(d.pf_score_json != ''){ }}@{{JSON.stringify(d.pf_score_json)}}@{{# }else{ }}@{{JSON.stringify(d.jc_score_json)}}@{{# } }}" style="display:none" >  
</script>
<script type="text/html" id="titleTpl2">  
    @{{# if(d.check_module_text != '无'){ }}
        @{{# if(d.module_info.length>0){ }}
            @{{#  layui.each(d.module_info, function(k, v){ }}
                <p>@{{v.name}}（@{{v.count}}条数据）<span class="module-see" data="@{{JSON.stringify(v)}}" style="float: right;color: #1e9fff;cursor: pointer;" >查看</span></p>
            @{{#  }); }}
        @{{# }else{ }}
            <p></p>
        @{{# } }}       
    @{{# }else{ }}
        <p></p>
    @{{# } }} 
</script>
@endpush

@section('content')
<style>
    .opt-panel{padding: 20px;}
    .panel-title h3{font-weight: 800;margin-bottom: 20px;}

    #add-form{padding: 20px 5px;}
    .opt-area{display: flex;flex-direction: row-reverse;padding: 10px 20px;margin-bottom: 20px;}
    .opt-area button{margin-left: 10px;}
    .layui-table td{border-left: 1px red solid;}
    #tips-view{margin: 30px;}
    #tips-view p{line-height: 38px;}
</style>

<div class="layui-row">
    <div class="layui-panel opt-panel">
        <div class="panel-title">
            <h3>学年考核 - 基本信息</h3>
        </div>
        <form class="layui-form" action="" lay-filter="formTest">
        <div class="layui-row" >
                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">学年学期：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="data_version_name" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">教师姓名：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="username" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px" >任教学科：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="subject" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">任教年级：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="grade" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">任班主任班级：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="class" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px" >职称：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" >
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">总分：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="zf" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">平均分：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="pjf" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 30%;">
                        <label class="layui-form-label" style="width:130px">排名：</label>
                        <div class="layui-input-inline" style="width: 59%;">
                        <input disabled type="text" name="rank" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

            </div>
            
            
        </form>
    </div>   
</div>


  
<div class="layui-row" style="margin-top:10px" >
    <div class="layui-panel opt-panel">
        <div class="panel-title">
            <h3>考核内容</h3>
        </div>

        <div class="layui-card">        
            <div class="layui-row">                    
                <div id="zuoye" class="layui-row">  
                    <form class="layui-form" action="" lay-filter="formTest2">                         
                        <table class="layui-table" id="tablelist" lay-filter="tablelist" ></table>
                    </form>  
                </div>  
            </div>       
        </div>
       
        <div class="layui-row">
                <div class="opt-area">
                    <a _href="" ><button class="layui-btn layui-btn-primary" id="fanhui" type="button">返回</button></a>
                    <button class="pear-btn pear-btn-primary" type="button" id="formDemo" lay-filter="formDemo">提交</button>
                </div> 
            </div>
    </div>
</div>

<div id="tips-view" style="display:none" >

</div>
@endsection